package de.graph.common.impl;

import de.graph.common.Edge;
import de.graph.common.Vertex;
import de.graph.document.Document;


final class EdgeImpl extends ElementImpl implements Edge {

    protected static final String IS_DIRECTED = "isDirected";
	protected static final String TARGET = "target";
	protected static final String SOURCE = "source";

	protected EdgeImpl(final Document document) {
        super(document);
    }
 
    public Vertex getSourceVertex() {
        return getDocument().getProperty(SOURCE);
    }

    public Vertex getTargetVertex() {
        return getDocument().getProperty(TARGET);
    }

    public boolean isDirected() {
        return getDocument().getProperty(IS_DIRECTED, true);
    }

    @Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		
		builder.append(getSourceVertex());
		if (isDirected()) {
			builder.append("--");
		}
		else {
			builder.append("<-");
		}
		builder.append(getLabel());
		builder.append("->");
		builder.append(getTargetVertex());
		
		return builder.toString();
	}
}
